package com.example.administrator.picturetest;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by Administrator on 2016/6/24.
 */

public class CustomView extends View {
    private Paint paint;

    public CustomView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        //绘制风格
        setViewPaint();
//        Path path = new Path();
//        path.moveTo(200, 200);
//        path.lineTo(100, 400);
//        path.lineTo(300, 400);
//        path.close();
//        canvas.drawPath(path, paint);
//        //
//        path.moveTo(100, 800);
//        path.lineTo(200, 500);
//        path.lineTo(300, 800);
//        path.lineTo(400, 500);
//        path.lineTo(500, 800);
//        canvas.drawPath(path, paint);
//        Path path = new Path();
//        //添加各种角度弧线
//        path.arcTo(100, 100, 300, 300, 0, 90, true);
//        canvas.drawPath(path, paint);

        paint.setStyle(Paint.Style.FILL);
        Path path = new Path();
        path.addCircle(150, 150, 100, Path.Direction.CW);
        Path path2 = new Path();
        path2.addCircle(300, 150, 100, Path.Direction.CW);
        path.op(path2, Path.Op.UNION);
        canvas.drawPath(path, paint);


    }

    private void setViewPaint() {
//绘制风格
        paint = new Paint();
        //去锯齿
        paint.setAntiAlias(true);
        //设置颜色
        paint.setColor(getResources().getColor(android.R.color.holo_blue_light));
        //设置风格为空心
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(10);

    }
}
